package com.achao.springbootinit.service.impl;

import com.achao.springbootinit.common.ErrorCode;
import com.achao.springbootinit.exception.BusinessException;
import com.achao.springbootinit.exception.ThrowUtils;
import com.achao.springbootinit.mapper.InterfaceInfoMapper;
import com.achao.springbootinit.model.dto.interfaceInfo.InterfaceInfoQueryRequest;
import com.achao.springbootinit.model.entity.InterfaceInfo;
import com.achao.springbootinit.model.vo.InterfaceInfoVO;
import com.achao.springbootinit.service.InterfaceInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
* @author 14276
* @description 针对表【interface_info(开发API接口信息表)】的数据库操作Service实现
* @createDate 2023-04-22 23:58:24
*/
@Service
public class InterfaceInfoServiceImpl extends ServiceImpl<InterfaceInfoMapper, InterfaceInfo>
    implements InterfaceInfoService {

    @Override
    public void validInterfaceInfo(InterfaceInfo interfaceInfo, boolean add) {
        if (interfaceInfo == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }

        String interfaceName = interfaceInfo.getInterfaceName();
        String interfaceUrl = interfaceInfo.getInterfaceUrl();
        String interfaceMethod = interfaceInfo.getInterfaceMethod();

        // 创建时，参数不能为空
        if (add) {
            ThrowUtils.throwIf(StringUtils.isAnyBlank(interfaceName,
                    interfaceUrl, interfaceMethod), ErrorCode.PARAMS_ERROR);
        }
        // 有参数则校验
        if (StringUtils.isNotBlank(interfaceName) && interfaceName.length() > 50) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "接口名过长");
        }
        if (StringUtils.isNotBlank(interfaceUrl) && interfaceUrl.length() > 8192) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "接口地址过长");
        }
    }
}




